โปรแกรมบ นท ก ช อ และ อ เมล โดยจ ดเก บข อม ลลงไปท SQLite



Similar documents
การตรวจสอบการต ดต งโปรแกรมสแกนเอกสารและการด ภาพสแกน ค ม อทางด านเทคน ค

Software Design and Development 1/2003

เอกสารประกอบการต ดต ง OpenOffice.org

(cluster01: และ cluster02: )

ภาพท 2 แสดงหน าการท ารายงานส นค าคงคล ง

การน าค าพ ก ด XY มาสร างข อม ล Point และ Polygon ด วยโปรแกรม ArcGIS 9.2

ค ม อการใช งาน (ส าหร บผ จ ดก จกรรม) โครงการ พ ฒนาระบบบร หารจ ดการฐานข อม ล เคร อข ายผ ม ส วนได เส ยในการประกอบก จการพล งงาน

การเช อมโยงภาพน ง ว ธ สร างการเช อมโยง

ค ม อการใช งานโปรแกรม

การใช โปรแกรม Microsoft PowerPoint 2010 คร อ มาพร บร ร กษ

การแปลค าพ ก ดจากลองจ จ ดละต จ ดท เป น องศา ล ปดา ฟ ล ปดา ให เป นทศน ยม

User Manual Editor Tool Proposal V1.0

ค ม อว ธ การต งค าเคร องถ ายเอกสาร ให ใช งานฟ งก ช น Scan และว ธ ต ดต งโปรแกรมท ใช ในการ Scan

ค ม อการใช งานระบบ E-Office ระบบสาน กงานอ เล คทรอน คส

Nature4thai Application

การแก ไขข อม ลอ ตราใน ท าเน ยบก าล งพลอ เล กทรอน กส ปร บปร ง เม อ 12 ก.ย. 57

ท างานก บข อม ล การเล อนต าแหน ง

การเช อมโยงระหว างเว บบล อกก บข อม ลบน Server กรมการพ ฒนาช มชน โดย ผด งศ กย ข นเจร ญ ห วหน ากล มงานสารสนเทศการพ ฒนาช มชน

By Dr Nongphanga Khunajukr Ms Buasai Petsuriyawong Mr.Knok Wongrutpunya. Department of Microbiology

ค ม อการส ารองระบบจดหมายอ เล กทรอน กส กรมโยธาธ การและผ งเม อง และ

ค ม อการใช งานเว บไซต สาเร จร ป. FreeWebFree.com

การน า Dropbox มาใช ในการท างาน ส าน กงานว ทยาเขตจ กรพงษภ วนารถ

เอกสารประกอบการเร ยน เร อง คอมพ วเตอร น าร

การใช งาน Microsoft Access การเร ยกใช โปรแกรม Start > All Programs > Microsoft Office > Microsoft Office Access 2007

บทท 3 ระบบการแจ งข าวสารประชาส มพ นธ อ เล กทรอน กส

การสร าง point จากพ ก ด ละต จ ด ลองจ จ ด

เป นเมน ท ใช ในการจ ดการภาพเอกกสาร โดยม รายละเอ ยดด งน

ค ม อการส ารองระบบจดหมายอ เล กทรอน กส กรมโยธาธ การและผ งเม อง และ

การ Activate Windows 7, Windows 8 และ Office 2010 แบบภายใน โดยใช Campus Licenses

การจ ดการระบบต ดต อเราโดย Web Admin สามารถแบ งออกเป น 6 ห วข อ ด งน

การอบรมท า Mindmap ด วยคอมพ วเตอร ความหมาย เป นแผนผ ง ( Diagram ) ใช เพ อแสดงค า หร อแนวความค ดของมน ษย ท เช อมโยงความค ด ต าง ๆ จากศ นย กลาง ถ กสร

ค ม อการใช งานOneDrive

ค ม อการใช งานระบบงานสารบรรณ E-Office ส าน กงานสาธารณส ขจ งหว ดพ ษณ โลก

ค ม อการต ดต งส อการเร ยนช นประถมศ กษาป ท 2 ในคอมพ วเตอร พกพา (Tablet)

ค ม อการใช งานโปรแกรม Flip Album Vista Pro 7.0

การจ ดการก บแฟ มข อม ล จ ดเก บเอกสาร (Save)

การต ดต งโปรแกรม ส าหร บระบบจ ดเก บเอกสารอ เล กทรอน กส. (Electronic Document Management System: EDMS)

คล กท ป ม เม อต องการยกเล กการลบข อม ล คล กท ป ม เม อต องการลบข อม ล จะแสดงหน าจอด งร ป

ค ม อการใช ระบบบร หารเน อหารายงาน

เอกสารประกอบการเร ยน รายว ชาเพ มเต ม ว ชาคอมพ วเตอร เร อง MicrosoftWord 2010 ประส ทธ อ ดหน น โรงเร ยนบ านเม องแก

E Office ส าน กงานเขตพ นท การศ กษานครราชส มา เขต 6

การสร างบทเร ยน e-learning ด วย Captivate

ภาคผนวก ค ค ม อการใช งานโปรแกรมประย กต

ค ม อการต ดต งโปรแกรม Mis-School

ปฏ บ ต การสารวจเส นทาง

ค ม อ กระทรวงศ กษาธ การ สาน กงานคณะกรรมการการอาช วศ กษา

How To Use Powerpoint And Powerpoint 2.2 On A Computer Or Tablet

บทท 4 การจ ดการทร พยากร (Resource)

ค ม อระบบงานสารบรรณอ เล กทรอน กส ซ - 1 ภาคผนวก ซ

ข นตอนการต ดต งระบบปฏ บ ต การ Microsoft Windows XP Professional โดยใช โปรแกรมจ าลอง (VMware Workstratitioin)

ค ม อการใช งานโปรแกรมบร หารจ ดการงบประมาณโครงการ

ค ม อการใช งานผ ค าก บภาคร ฐ (Electronic Bidding : e-bidding)

ร จ กก บเว บเพจ ใช ข อความเป นล งค ใช ร ปภาพเป นล งค

การน าข อม ลเข าโปรแกรม ACL/CATs ส าหร บโปรแกรมระบบบ ญช สหกรณ ออมทร พย Version 2

ล าด บการสร างไฟล ประมวลผล

ค ม อ ระบบบร หารโปรแกรมงานทะเบ ยนและว ดผลการศ กษา ส าหร บผ ด แลระบบ

การต ดต งระบบ Supreme2004 บนระบบปฏ บ ต การ Windows 7

การต ดต งโปรแกรม ArcGIS 9.x ข นตอนการเช คระบบเคร องคอมพ วเตอร ก อนลงโปรแกรม

ใบความร เร อง การสร างเว บเพจใหม (New Site)

ค ม อการใช งาน BLS iexcel

ส วนเจ าหน าท ผ บทท 1 ส าน กบร หารงานกลาง น าเข าข อม ล ท วไป จ งเล อนเง นเด อนน ก ไขข อม ลผลการ ดรอบการประ ม น 2. เล อกป งบประมาณ 1-1 โดย บร ษ ท

Pivot Table และ Pivot Chart... 1 ต วอย างท ข นตอนการสร าง Pivot Table และ Pivot Chart... 6 ต วอย างท

เอกสารประกอบการสอน. รายว ชา การใช โปรแกรม Authorware 7 (ง 30203) นายร งโรจน เจนเจตว ทย

ค ม อการใช งาน สาหร บสถาบ นการศ กษา

ค ม อการปฎ บ ต งานโปรแกรม Turnitin ส าหร บผ แลระบบ (Administrator)

1. Lync ท ำไมต อง Lync 2013

ก จกรรมท 2.1 ทบทวนการใช งานโปรแกรมระบบปฏ บ ต การ Windows 95 และการเร ยกใช งานโปรแกรมเอ กเซล

ค ม อการใช งาน ระบบการบร หารจ ดการบร การทางการศ กษา ระด บว ทยาเขต ส าหร บอาจารย ส าหร บอาจารย

ค ม อการใช งาน PIA Excel Input Template เบ องต น ฝ ายสถ ต และข อสนเทศ -1-

ค ม อการใชงาน SMS Corporate (

P2 การใช งานโปรแกรม P2

How To Download Polis From Pc Or Mac Or Mac (Windows Xp) On Pc Or Ipad) On A Microsoft Mac Or Ipa (Windows) On An Ipa Or Ipam (Windows V

ปฏ บ ต การคร งท 6 การใช โปรแกรมส าน กงาน คร งท 4

เม อเข าระบบตามหน วยงานแล ว จะพบหน าจอ ระบบจ ดการเว บไซต

การบ นท กโน ตดนตร ไทยด วยโปรแกรมส าเร จร ป Microsoft Excel

5. การใช งานระบบ e-office ผ านอ ปกรณ Tablet: Samsung Galaxy Tab 10.1 ระบบปฏ บ ต การ Android version 3.1


การออกจากโปรแกรมฝ กพ มพ (Microsoft word)

โปรแกรมระบบเผยแพร ผลงาน และนว ตกรรมทางการศ กษา (E-innovation)

ค ม อการต ดต งโปรแกรม ระบบบร หารงานว จ ยแห งชาต แบบ Offline (NRPM Offline) ส าหร บเจ าหน าท หน วยงาน

How To Use A Powerpoint Powerpoint (Powerpoint 2) (Powerbook 2)

ระบบสารบรรณอ เล กทรอน กส

How To Get A Free Ride From A Car To The Beach

ค ม อการต ดต งโปรแกรม

การใช โปรแกรมจ ดท าเอกสารและหล กฐานทางการศ กษา (ปพ.1-9)

ค ม อการใช งาน ระบบ. NiMExpress (Android OS)


มหาว ทยาล ยราชภ ฏกาแพงเพชร. ค ม อการใช ระบบบร หารงานบ คคล แบบอ เล กทรอน กส (E-Personal) สาหร บงานธ รการ กองกลาง ส าน กงานอธ การบด

การสร างบทความ (Content)

How To Get A Job At A Bank

How To Get A Lotus Note

Transcription:

โปรแกรมบ นท ก ช อ และ อ เมล โดยจ ดเก บข อม ลลงไปท SQLite

Application => Single View Application => Next Product Name = ContactLite, Devices = iphone, Use Storyboards, Use Automatic Reference Counting

เล อกไปท TARGETS => Build Pharses => + เล อก libsqlite3.dylib เล อก Add

เป ดไฟล Contact.h #import <Foundation/Foundation.h> @interface Contact : NSObject NSString *pkid; NSString *name; NSString *email; @property(strong, nonatomic)nsstring *name; @property(strong, nonatomic)nsstring *email; @property(strong, nonatomic)nsstring *pkid; @end เป ดไฟล Contact.m #import "Contact.h" @implementation Contact @synthesize pkid,name,email; @end

วาง Navigation Bar, Table View, Table View Cell และ Bar Button Item ตาม ล าด บลงบนร ปด านล างน

คล กไปท Navigation Bar แล วเปล ยนค าของ Title = Contact

คล กไปท ป มตามร ปด านล าง Item แล วไปท ไอคอน Attribute เปล ยนค า Identifier = Add

เล อกไปคล กท Table View Cell ตามร ปด านล างน แล วไปเปล ยนค าของ Style = Subtitle, Identifier = Cell

เป ดไฟล ViewController.h ข นมา #import <UIKit/UIKit.h> #import "sqlite3.h" #import "Contact.h" @interface ViewController : UIViewController<UITableViewDataSource, UITableViewDelegate> NSArray *datalist; @property (weak, nonatomic) IBOutlet UINavigationItem *navitem; @property (weak, nonatomic) IBOutlet UITableView *tablev; @property (nonatomic, retain) NSArray *datalist; @property (strong, nonatomic) NSString *databasepath; @property (nonatomic) sqlite3 *contactdb; -(void)setupdatabase; -(void)loaddatabase; -(void)deletecontact:(nsstring *)pkid; @end

เป ดไฟล ViewController.m ข นมา #import "ViewController.h" #import "SaveViewController.h" @interface ViewController () @end @implementation ViewController @synthesize datalist, tablev; @synthesize databasepath, contactdb; @synthesize navitem; -(void)setupdatabase // Get the documents directory NSArray *dirpaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docsdir = dirpaths[0]; // Build the path to the database file databasepath = [[NSString alloc] initwithstring: [docsdir stringbyappendingpathcomponent: @"contacts.db"]]; NSFileManager *filemgr = [NSFileManager defaultmanager]; if ([filemgr fileexistsatpath: databasepath] == NO) const char *dbpath = [databasepath UTF8String]; if (sqlite3_open(dbpath, &contactdb) == SQLITE_OK) char *errmsg; const char *sql_stmt = "CREATE TABLE IF NOT EXISTS CONTACTS (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, EMAIL TEXT)"; if (sqlite3_exec(contactdb, sql_stmt, NULL, NULL, &errmsg)!= SQLITE_OK) NSLog(@"Failed to create table");

เป ดไฟล ViewController.m - (ต อ) -(void)loaddatabase NSMutableArray *data = [NSMutableArray array]; sqlite3_stmt *statement; NSString *querysql = @"SELECT id, name, email FROM contacts"; const char *query_stmt = [querysql UTF8String]; const char *dbpath = [databasepath UTF8String]; if (sqlite3_open(dbpath, &contactdb) == SQLITE_OK) sqlite3_prepare_v2(contactdb, query_stmt, -1, &statement, NULL); while (sqlite3_step(statement) == SQLITE_ROW) NSString *Id = [[NSString alloc]initwithutf8string:(const char *) sqlite3_column_text(statement, 0)]; NSString *name = [[NSString alloc]initwithutf8string:(const char *) sqlite3_column_text(statement, 1)]; NSString *email = [[NSString alloc]initwithutf8string:(const char *) sqlite3_column_text(statement, 2)]; Contact *row = [[Contact alloc] init]; row.pkid = Id; row.name = name; row.email = email; [data addobject:row]; datalist = [NSMutableArray arraywitharray:data]; sqlite3_finalize(statement);

เป ดไฟล ViewController.m - (ต อ) - (void)viewdidload [super viewdidload]; navitem.leftbarbuttonitem = self.editbuttonitem; [self setupdatabase]; [self loaddatabase]; -(void)viewdidappear:(bool)animated [super viewdidappear:yes]; [self setupdatabase]; [self loaddatabase]; [tablev reloaddata]; - (void)didreceivememorywarning [super didreceivememorywarning]; // Dispose of any resources that can be recreated. -(NSInteger)tableView:(UITableView *)tableview numberofrowsinsection:(nsinteger)section return datalist.count;

เป ดไฟล ViewController.m - (ต อ) -(UITableViewCell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath static NSString *cellid = @"Cell"; UITableViewCell *cell = [tableview dequeuereusablecellwithidentifier:cellid]; if (cell == nil) cell = [[UITableViewCell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellid]; Contact *row = (Contact *)[datalist objectatindex:indexpath.row]; cell.textlabel.text = [NSString stringwithformat:@"%@-%@", row.pkid, row.name]; cell.detailtextlabel.text = row.email; return cell;

เป ดไฟล ViewController.m - (ต อ) -(void)tableview:(uitableview *)tableview commiteditingstyle: (UITableViewCellEditingStyle)editingStyle forrowatindexpath:(nsindexpath *)indexpath if (editingstyle == UITableViewCellEditingStyleDelete) Contact *row = [datalist objectatindex:indexpath.row]; NSMutableArray *array = [NSMutableArray arraywitharray:datalist]; [array removeobject:row]; datalist = array; [self deletecontact:row.pkid]; [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationautomatic]; -(void)prepareforsegue:(uistoryboardsegue *)segue sender: (id)sender SaveViewController *vc = (SaveViewController *)segue.destinationviewcontroller; vc.databasepath = self.databasepath; vc.contactdb = self.contactdb; -(void)setediting:(bool)editing animated:(bool)animated [super setediting:editing animated:animated]; [tablev setediting:editing animated:animated];

เป ดไฟล ViewController.m - (ต อ) -(UITableViewCellEditingStyle)tableView:(UITableView *)tableview editingstyleforrowatindexpath:(nsindexpath *)indexpath if (tablev.editing) return UITableViewCellEditingStyleDelete; return UITableViewCellEditingStyleNone; -(void)deletecontact:(nsstring *)pkid sqlite3_stmt *statement; const char *dbpath = [databasepath UTF8String]; if (sqlite3_open(dbpath, &contactdb) == SQLITE_OK) NSString *SQL = @"DELETE FROM CONTACTS WHERE ID= \"%@\""; NSString *deletesql = [NSString stringwithformat:sql, pkid]; const char *delete_stmt = [deletesql UTF8String]; sqlite3_prepare_v2(contactdb, delete_stmt,-1, &statement, NULL); if (sqlite3_step(statement)!= SQLITE_DONE) NSLog(@"DELETE FAILED"); sqlite3_finalize(statement); sqlite3_close(contactdb); @end

ต งค า Class = SaveViewController และ Subclass of = UIViewController เป ดไฟล SaveViewController.h #import <UIKit/UIKit.h> #import "sqlite3.h" @interface SaveViewController : UIViewController<UITextFieldDelegate> - (IBAction)doSaveClick:(id)sender; @property (weak, nonatomic) IBOutlet UITextField *tfname; @property (weak, nonatomic) IBOutlet UITextField *tfemail; @property (strong, nonatomic) NSString *databasepath; @property (nonatomic) sqlite3 *contactdb; @end

เป ดไฟล SaveViewController.m #import "SaveViewController.h" @interface SaveViewController () @end @implementation SaveViewController @synthesize tfname, tfemail; @synthesize databasepath, contactdb; -(BOOL)textFieldShouldReturn:(UITextField *)textfield [textfield resignfirstresponder]; return YES; - (id)initwithnibname:(nsstring *)nibnameornil bundle: (NSBundle *)nibbundleornil self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) // Custom initialization return self; - (void)viewdidload [super viewdidload];! // Do any additional setup after loading the view. [tfname becomefirstresponder]; - (void)didreceivememorywarning [super didreceivememorywarning]; // Dispose of any resources that can be recreated.

- (IBAction)doSaveClick:(id)sender sqlite3_stmt *statement; const char *dbpath = [databasepath UTF8String]; if (sqlite3_open(dbpath, &contactdb) == SQLITE_OK) NSString *SQL = @"INSERT INTO CONTACTS (name, email) VALUES (\"%@\",\"%@\")"; NSString *insertsql = [NSString stringwithformat:sql, tfname.text, tfemail.text]; const char *insert_stmt = [insertsql UTF8String]; sqlite3_prepare_v2(contactdb, insert_stmt,-1, &statement, NULL); if (sqlite3_step(statement) == SQLITE_DONE) [self dismissviewcontrolleranimated:yes completion:nil]; else NSLog(@"SAVE FAILED"); sqlite3_finalize(statement); sqlite3_close(contactdb); @end

ท าการเช อมโยงหน าจอด งร ปด านล างเข าไปเช อมก บ navitem ท าการเช อมโยงหน าจอด งร ปด านล างเข าไปเช อมก บ tablev

ท าการคล กขวาท Table View แล วท าการเช อม datasource และ delegate ไปย งไอคอนส เหล องด านล างด งภาพ

วาง View Controller ด งร ปไปบน MainStoryboard.Storyboard

คล กขวาท ไอคอนส เหล องด งร ปด านล าง แล วท าการเช อ modal ไป ย งไอคอน +

คล กขวาท ไอคอนส เหล องด งร ปด านล าง แล วไปเล อกไอคอนท 3 ตามร ปแล วท าการเปล ยน Class = SaveViewController

วาง Label 2 อ นต งค า Text = NAME, EMAIL ตามร ป วาง Text Field 2 อ น และ ป มต งค า Text = SAVE